package com.lu.system.management.service.impl;

import com.lu.system.management.dao.UserRoleDao;
import com.lu.system.management.domain.UserRoleDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.lu.system.management.dao.UserDao;
import com.lu.system.management.domain.UserDO;
import com.lu.system.management.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserDao userDao;
	@Autowired
	private UserRoleDao userRoleDao;
	
	@Override
	public UserDO get(Long userId){
		return userDao.get(userId);
	}
	
	@Override
	public List<UserDO> list(Map<String, Object> map){
		return userDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return userDao.count(map);
	}
	
	@Override
	public int save(UserDO user){
		try{
			userDao.save(user);
			UserRoleDO userRoleDO = new UserRoleDO();
			userRoleDO.setUserId(user.getUserId());
			userRoleDO.setRoleId(2L);
			userRoleDao.save(userRoleDO);
		}catch (Exception e){
			return 0;
		}
		return 1;
	}

    @Override
    public void saveBatch(List<UserDO> user) throws Exception {
		userDao.saveBatch(user);
    }
	
	@Override
	public int update(UserDO user){
		return userDao.update(user);
	}

    @Override
    public void updateBatch(List<UserDO> user) throws Exception {
		userDao.updateBatch(user);
    }
	
	@Override
	public int remove(Long userId){
		return userDao.remove(userId);
	}
	
	@Override
	public int batchRemove(Long[] userIds){
		return userDao.batchRemove(userIds);
	}
	
}
